package com.qfedu.fmmll.submit.controller;

import com.github.wxpay.sdk.WXPay;
import com.qfedu.fmmall.common.status.ResStatus;
import com.qfedu.fmmall.common.vo.ResultVO;
import com.qfedu.fmmall.entity.Orders;
import com.qfedu.fmmll.submit.service.OrderSubmitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : yanBin
 * @date :2022/2/10 15:42
 */
@RestController
@CrossOrigin
@RequestMapping("/order")
@Api(value = "订单页面所需接口", tags = "订单管理")
public class OrderSubmitController {

    @Autowired
    private OrderSubmitService orderSubmitService;

    @PostMapping("/add")
    @ApiOperation("添加订单接口")
    public ResultVO addOrders(String cids, @RequestBody Orders orders ) {
        try {
            Map<String, String> map = orderSubmitService.addOrders(cids, orders);
/**            WXPay wxPay = new WXPay(new MyPayConfig());
            Map<String, String> data = new HashMap();
            data.put("body", map.get("productNames"));           //商品描述
            data.put("out_trade_no", map.get("orderId"));    //使用当前用户订单编号作为当前支付的交易号
            data.put("fee_type", "CNY");          //支付币种
            //data.put("total_fee", String.valueOf(orders.getActualAmount()*100));           //支付金额
            data.put("total_fee", "1");           //支付金额
            data.put("trade_type", "NATIVE");      //交易类型
            data.put("notify_url", "/pay/callback"); //设置支付完成时的回调接口

            //发送请求，获取响应
            Map<String, String> resp = wxPay.unifiedOrder(data);
            map.put("payUrl",resp.get("code_url"));
 */
            return new ResultVO(ResStatus.OK.ordinal(), "添加订单成功",map);
        } catch (Exception e) {
            return new ResultVO(ResStatus.NO.ordinal(), "添加订单失败", null);
        }
    }

}
